package cn.sccdlg.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/10/24 22:01
 * 运用拦截器处理登录逻辑的用户Controller
 */
@Controller
@RequestMapping("/user")
public class UserController {

    //登陆页面
    @RequestMapping("/login")
    public String login(Model model) {
        return "login";
    }

    //登陆提交
    //userId：用户账号， pwd：密码
    @RequestMapping("/login/submit")
    public String loginSubmit(HttpSession session, String userId, String pwd) {
        //向 session 记录用户身份信息
        session.setAttribute("activeUser", userId);
        session.setAttribute("activePass", pwd);
        return "main";
    }

    //退出
    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        //session 过期
        session.invalidate();
        return "redirect:/index.jsp";
    }

    //菜单权限页面
    @RequestMapping("/main")
    public String main() {
        System.out.println("直接访问菜单权限页面");
        return "main";
    }
}
